<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	/**
     * 
     * This puts the application.ini setting in the registry
     */
    protected function _initConfig()
    {
        Zend_Registry::set('config', $this->getOptions());
    }

	
	protected function _initDoctype()
	{
		Zend_Layout::startMvc();
		$this->bootstrap('view');
		$view = $this->getResource('view');
		$view->headTitle('Youtajeer.com');
		$view->doctype('XHTML1_STRICT');
		$view->headScript()->prependFile('http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js');
		//TODO find issue tu the javascript code 
		$view->headScript()->appendScript("$(function (){ $('.info').tooltip(); }); ");
		$view->headScript()->appendScript("$(function ()
		{ $('.popright').popover({trigger: 'hover'});
		});");
		$view->headScript()->appendScript('$(document).ready(function(){

												$(".span8 input").click(function(){
												  $("#panel").show();
												  
												});
												
												
											});');
		
	}
	
	/**
	 * initialize the application router 
	 * 
	 * @return Zend_Controller_Router_Interface
	 */
	protected function _initRouter()
	{
		// Récupère l'instance courante du router actuel si il existe sinon en créer un
		$router = Zend_Controller_Front::getInstance()->getRouter();
		
 
		$providerRoute = new Zend_Controller_Router_Route('login/:provider',
				array(
						'controller' => 'login',
						'action' => 'index'
				));
		$router->addRoute('login/:provider', $providerRoute);
		$logoutRoute = new Zend_Controller_Router_Route('login/logout',
				array(
						'controller' => 'login',
						'action' => 'logout'
				));
		$router->addRoute('logout', $logoutRoute);
		$viewRoute = new Zend_Controller_Router_Route_Regex(
				'view/(.+)/(\d+)-(.+)',
				array(
						'controller' => 'view',
						'action'     => 'index'
				),
				array(
						1 => 'class',
						2 => 'id_object', 
						3 => 'name'
				),
				'view/%s/%d-%s'
		);
		$router->addRoute('View', $viewRoute);
		
		$objects = array( 	'1'		=> 'other',
							'2'		=> 'book',
							'3'		=> 'house',
							'4'		=> 'parking',
							'5'		=> 'apartment',
							'6'		=> 'land',
							'7'		=> 'car',
							'8'		=> 'motorcycle',
							'9'		=> 'desktop',
							'10'		=> 'laptop',
							'11'		=> 'phone',
							'12'		=> 'tv',
							'13'		=> 'clothing',
						);
		
		foreach ($objects as $object){
			$editObjectRoute = new Zend_Controller_Router_Route_Regex(
					'object/('.$object.')/(\d+)-(.+)',
					array(
							'controller' => 'object',
							'action'     => $object
					),
					array(
							1 => 'class',
							2 => 'id_object',
							3 => 'name'
					),
					'object/%s/%d-%s'
			);
			$router->addRoute('edit'.$object, $editObjectRoute);
		}
		
//@TODO to delete
// 		$editHouseRoute = new Zend_Controller_Router_Route_Regex(
// 				'object/(house)/(\d+)-(.+)',
// 				array(
// 						'controller' => 'object',
// 						'action'     => 'house'
// 				),
// 				array(
// 						1 => 'class',
// 						2 => 'id_object',
// 						3 => 'name'
// 				),
// 				'object/%s/%d-%s'
// 		);
// 		$router->addRoute('edithouse', $editHouseRoute);
		
// 		$editCarRoute = new Zend_Controller_Router_Route_Regex(
// 				'object/(car)/(\d+)-(.+)',
// 				array(
// 						'controller' => 'object',
// 						'action'     => 'car'
// 				),
// 				array(
// 						1 => 'class',
// 						2 => 'id_object',
// 						3 => 'name'
// 				),
// 				'object/%s/%d-%s'
// 		);
// 		$router->addRoute('editcar', $editCarRoute);
		
// 		$editApartmentRoute = new Zend_Controller_Router_Route_Regex(
// 				'object/(apartment)/(\d+)-(.+)',
// 				array(
// 						'controller' => 'object',
// 						'action'     => 'apartment'
// 				),
// 				array(
// 						1 => 'class',
// 						2 => 'id_object',
// 						3 => 'name'
// 				),
// 				'object/%s/%d-%s'
// 		);
// 		$router->addRoute('editapartment', $editApartmentRoute);
		
// 		$editLandRoute = new Zend_Controller_Router_Route_Regex(
// 				'object/(land)/(\d+)-(.+)',
// 				array(
// 						'controller' => 'object',
// 						'action'     => 'land'
// 				),
// 				array(
// 						1 => 'class',
// 						2 => 'id_object',
// 						3 => 'name'
// 				),
// 				'object/%s/%d-%s'
// 		);
// 		$router->addRoute('editland', $editLandRoute);
		
// 		$editParkingRoute = new Zend_Controller_Router_Route_Regex(
// 				'object/(parking)/(\d+)-(.+)',
// 				array(
// 						'controller' => 'object',
// 						'action'     => 'parking'
// 				),
// 				array(
// 						1 => 'class',
// 						2 => 'id_object',
// 						3 => 'name'
// 				),
// 				'object/%s/%d-%s'
// 		);
// 		$router->addRoute('editparking', $editParkingRoute);
		
// 		$editMotorcycleRoute = new Zend_Controller_Router_Route_Regex(
// 				'object/(motorcycle)/(\d+)-(.+)',
// 				array(
// 						'controller' => 'object',
// 						'action'     => 'motorcycle'
// 				),
// 				array(
// 						1 => 'class',
// 						2 => 'id_object',
// 						3 => 'name'
// 				),
// 				'object/%s/%d-%s'
// 		);
// 		$router->addRoute('editmotorcycle', $editMotorcycleRoute);
		
		$rentRoute = new Zend_Controller_Router_Route_Regex(
				'offer/rent/(.+)/(\d+)-(.+)',
				array(
						'controller' => 'offer',
						'action'     => 'rent'
				),
				array(
						1 => 'class',
						2 => 'id_object',
						3 => 'name'
				),
				'offer/rent/%s/%d-%s'
		);
		$router->addRoute('rentRoute', $rentRoute);
		
		$saleRoute = new Zend_Controller_Router_Route_Regex(
				'offer/sale/(.+)/(\d+)-(.+)',
				array(
						'controller' => 'offer',
						'action'     => 'sale'
				),
				array(
						1 => 'class',
						2 => 'id_object',
						3 => 'name'
				),
				'offer/sale/%s/%d-%s'
		);
		$router->addRoute('saleRoute', $saleRoute);
		
		$profilRoute = new Zend_Controller_Router_Route_Regex(
				'profil/(\d+)',
				array(
						'controller'	=> 'profil',
						'action'		=> 'index'
				),
				array(
						1 => 'id_user'
				),
				'profil/%d'
		);
		$router->addRoute('profilRoute', $profilRoute);
		
		$deleteRoute = new Zend_Controller_Router_Route_Regex(
				'delete/(.+)/(\d+)-(.+)/(.+)',
				array(
						'controller' => 'delete',
						'action'     => 'index'
				),
				array(
						1 => 'class',
						2 => 'id_object',
						3 => 'name',
						4 => 'token'
				),
				'delete/%s/%d-%s/%s'
		);
		$router->addRoute('deleteRoute', $deleteRoute);
		
		$deleteReqRoute = new Zend_Controller_Router_Route_Regex(
				'delete/request/(\d+)/(.+)',
				array(
						'controller' => 'delete',
						'action'     => 'request'
				),
				array(
						1 => 'id_request',
						2 => 'token'
				),
				'delete/request/%d/%s'
		);
		$router->addRoute('deleteReqRoute', $deleteReqRoute);
		
		$deleteOfferRoute = new Zend_Controller_Router_Route_Regex(
				'delete/offer/(\d+)/(.+)',
				array(
						'controller' => 'delete',
						'action'     => 'offer'
				),
				array(
						1 => 'id_offer',
						2 => 'token'
				),
				'delete/offer/%d/%s'
		);
		$router->addRoute('deleteOfferRoute', $deleteOfferRoute);
 
		$requestRoute = new Zend_Controller_Router_Route(
				'request/:id_request',
				array(
						'controller' => 'request',
						'action'     => 'index'
				),
				array('id_request' => '\d+')
		);
		 
		$router->addRoute('requestRoute', $requestRoute);
		
		$viewLocTreeRoute = new Zend_Controller_Router_Route(
				'view/loctree',
				array(
						'controller' => 'view',
						'action'     => 'loctree'
				)
				
		);
		$router->addRoute('ViewLocTree', $viewLocTreeRoute);
		
		$viewRequestRoute = new Zend_Controller_Router_Route(
				'request/request',
				array(
						'controller' => 'request',
						'action'     => 'request'
				)
		
		);
		$router->addRoute('viewRequest', $viewRequestRoute);
    	
    	return $router;
	}
	
	protected function _initSession() {
		// initialise la session
// 		Zend_Session::setOptions(array(
// 		/*  stockage          */     	'save_path'         => 'repertoire_de_stockage',
// 		/* protection XSS */       		'cookie_httponly'   => true,
// 		/* durée vie    */            	'gc_maxlifetime'    => 5*60  // 60 secondes
// 		));
	
		//Zend_Session::start();
		// namespace après démarrage de la session
// 		$session = new Zend_Session_Namespace('vivier');
// 		$token = new Zend_Session_Namespace('token');
// 		$token->delete = md5(time()*rand(1,10));
// 		Zend_Registry::set('token', $token);
// 		return $token;
	}
	
	protected function _initMails()
	{
		$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'mail');
		$mailConfig = $config->toArray();
	
		Zend_Registry::set('Mail_Config', $mailConfig['mail']['config']);
	}
	
	


}

